package com.headwind.mq.activemq.consumer;

import com.google.gson.Gson;
import com.headwind.entity.HwMood;
import com.headwind.service.HwMoodService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

/**
 * @author : Headwind
 * @version : 1.0
 * @date : Created in 2020/8/10
 * @description : 消息消费者
 */
@Component
@Log4j2
public class HwMoodConsumer {
    private final HwMoodService hwMoodService;

    @Autowired
    public HwMoodConsumer(HwMoodService hwMoodService) {
        this.hwMoodService = hwMoodService;
    }

    @JmsListener(destination = "hw.queue")
    public void receiver(String message) {
        log.info("用户发表说说【" + message + "】成功");
    }

    @JmsListener(destination = "hw.queue.async.save")
    public void receiver(HwMood hwMood) {
        hwMoodService.save(hwMood);
        log.info("新消息已经被处理成功啦！消息是：" + new Gson().toJson(hwMood));
    }

}
